*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Figures Counterfactuals
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
 
 
#delimit ;

*local sigma="8e-05";   * Low risk aversion ;
local sigma="0.000428";  * Baseline ;

clear;
cap log close;
log using graphs_`sigma'.log, text replace;
if "`sigma'"=="0.000428" local addstr="";
  else local addstr="_sigma`sigma'";

set scheme s2mono;
graph set window fontface "Times New Roman";
insheet using Counterfactuals/counter_output_`sigma'.csv;

local exp0="Baseline estimates";
local exp1="Baseline without premium risk";
local exp2="Community rating, {&beta}=0";
local exp3="Observed {&beta} with FEs";
local exp4="Observed {&beta} without FEs";
local exp5="Full experience rating, {&beta}={&gamma}";
local exp6="Baseline if individual market";

label variable year "Years after enrollment";
forvalues X=0/6 {;
  label variable exp`X'_sd_premium "`exp`X''";
  label variable exp`X'_sd_expend "`exp`X''";
  label variable exp`X'_incomeloss "`exp`X''";
};

qui forvalues X=0/6 {;
  summ exp`X'_incomeloss if year>0;
  local certeq`X'=r(mean);
  summ exp`X'_sd_premium if year>0;
  local sd_premium`X'=r(mean);
};

disp "Baseline risk `certeq0'";
disp "Baseline no idiosyncratic risk `certeq1'";
disp "Community rating risk `certeq2'";
disp "Full experience rating risk `certeq5'";

disp "Baseline gain fraction " (1-(`certeq0'-`certeq2')/(`certeq5'-`certeq2'));

disp "FE beta risk `certeq3'";

disp "Baseline if individual risk `certeq6'; difference " (`certeq6'-`certeq0');

disp "Baseline sd premium `sd_premium0'";
disp "Baseline no idiosyncratic risk sd premium `sd_premium1'";
disp "Community rating sd premium `sd_premium2'";
disp "Full experience rating  sd premium `sd_premium5'";

qui sum exp0_sd_expend if year==0;
disp "Initial year SD on expenditures is " r(mean);
 
twoway (connected exp0_sd_premium year, lpattern(solid)) 
(connected exp1_sd_premium year, lpattern(dash)) 
  (connected exp2_sd_premium year, lpattern(dash_dot)) 
 (connected exp5_sd_premium year, lpattern(shortdash)),
  ytitle(Dollars per year);
graph export sd_premium`addstr'.pdf, replace;

twoway (connected exp0_sd_expend year, lpattern(solid)) 
  (connected exp1_sd_expend year, lpattern(dash))
  (connected exp2_sd_expend year, lpattern(dash_dot))
  (connected exp5_sd_expend year, lpattern(shortdash)),
  yscale(range (0 3500)) ylabel (#6) ytitle(Dollars per year);
graph export sd_expend`addstr'.pdf, replace;

local max=8000;
if "`sigma'"=="8e-05" local max=1000;
twoway (connected exp0_incomeloss year, lpattern(solid)) 
  (connected exp1_incomeloss year, lpattern(dash))
  (connected exp2_incomeloss year, lpattern(dash_dot))
  (connected exp5_incomeloss year, lpattern(shortdash)),
  yscale(range (0 `max')) ylabel(#5) ytitle(Dollars per year);
graph export incomeloss`addstr'.pdf, replace;

twoway (connected exp2_incomeloss year, lpattern(solid)) 
  (connected exp3_incomeloss year, lpattern(dash))
  (connected exp4_incomeloss year, lpattern(dash_dot))
  (connected exp5_incomeloss year, lpattern(shortdash)),
  yscale(range (0 `max')) ylabel(#5) ytitle(Dollars per year);
graph export passthrough_only_incomeloss`addstr'.pdf, replace;

local max=6000;
if "`sigma'"=="8e-05" local max=1000;
twoway (connected exp0_incomeloss year, lpattern(solid)) 
  (connected exp6_incomeloss year, lpattern(dash)),
  yscale(range (0 `max')) ylabel(#5) ytitle(Dollars per year);
graph export indiv_smallgroup_incomeloss`addstr'.pdf, replace;


log close;
